package com.dj.mingkong.portal.biz.controller.music;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dj.mingkong.common.annotation.RequestLimit;
import com.dj.mingkong.common.infrastructure.base.dto.page.PageVo;
import com.dj.mingkong.common.infrastructure.base.dto.rest.RestResponse;
import com.dj.mingkong.common.microservice.UserContext;
import com.dj.mingkong.common.util.AssertUtils;
import com.dj.mingkong.common.util.SmartBeanCopy;
import com.dj.mingkong.portal.biz.controller.music.vo.request.BoxCollectAddVo;
import com.dj.mingkong.portal.biz.controller.music.vo.request.BoxCollectCancelVo;
import com.dj.mingkong.portal.biz.controller.music.vo.request.BoxCollectQueryVo;
import com.dj.mingkong.portal.biz.controller.music.vo.response.BoxCollectDetailVo;
import com.dj.mingkong.portal.biz.controller.music.vo.response.BoxCollectVo;
import com.dj.mingkong.portal.biz.service.music.BoxCollectService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 音乐盒收藏管理
 *
 * @author zenglonghui
 * @date: 2022/8/24 23:32
 */
@RestController
@RequestMapping("/box/collect")
public class BoxCollectController {
    @Resource
    private BoxCollectService boxCollectService;

    /**
     * 音乐盒收藏
     *
     * @param addVo {}
     * @return Boolean
     */
    @PostMapping("/handle")
    @RequestLimit(count = 10)
    public RestResponse<Boolean> handle(@RequestBody @Validated BoxCollectAddVo addVo) {
        boxCollectService.handle(addVo);
        return RestResponse.buildSuccess();
    }

    /**
     * 添加音乐盒收藏
     *
     * @param addVo {}
     * @return Boolean
     */
    @PostMapping("/add")
    @RequestLimit(count = 10)
    public RestResponse<Boolean> add(@RequestBody @Validated BoxCollectAddVo addVo) {
        boxCollectService.add(addVo);
        return RestResponse.buildSuccess();
    }

    /**
     * 获取音乐盒收藏信息
     *
     * @param boxId 音乐盒id
     * @return 是否成功，true-成功，false-失败
     */
    @GetMapping("/getBoxCollect/{boxId}")
    public RestResponse<BoxCollectDetailVo> getBoxCollect(@PathVariable("boxId") Long boxId) {
        return RestResponse.success(boxCollectService.getBoxCollect(boxId));
    }

    /**
     * 分页查询我的收藏音乐盒列表
     *
     * @param queryVo {}
     * @return BoxVo
     */
    @PostMapping("/pageByVo")
    public RestResponse<PageVo<BoxCollectVo>> pageByVo(@RequestBody BoxCollectQueryVo queryVo) {
        AssertUtils.checkQueryPageVo(queryVo);
        queryVo.setUserId(UserContext.getUserId());
        final Page<BoxCollectVo> boxCollectVoPage = boxCollectService.pageByVo(queryVo);
        final PageVo<BoxCollectVo> pageVo = SmartBeanCopy.copyPageVo(boxCollectVoPage, BoxCollectVo.class);
        return RestResponse.success(pageVo);
    }

    /**
     * 取消收藏歌单
     *
     * @param cancelVo {}
     * @return Boolean
     */
    @PostMapping("/cancel")
    @RequestLimit(count = 5)
    public RestResponse<Boolean> cancel(@RequestBody @Validated BoxCollectCancelVo cancelVo) {
        boxCollectService.cancel(cancelVo);
        return RestResponse.buildSuccess();
    }
}
